//
//  GSCommonLoginBaseController.m
//  GSLoginDemo
//
//  Created by guoshikeji_a on 2018/7/27.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "GSCommonLoginBaseController.h"

@interface GSCommonLoginBaseController ()

@end

@implementation GSCommonLoginBaseController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    if (@available(iOS 11.0, *)) {
        
    }else {
        self.automaticallyAdjustsScrollViewInsets = false;
    }
    //
    self.customNaviBar = [GSCommonLoginCustomNaviBar new];
    self.customNaviBar.backgroundColor = [UIColor whiteColor];
    self.customNaviBar.leftButton.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 7);
    [self.customNaviBar.leftButton setImage:[UIImage imageNamed:@"gscommon_login_navi_back"] forState:UIControlStateNormal];
    self.customNaviBar.leftButton.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
    [self.customNaviBar.leftButton setTitleColor:GSLOGINRGBRGBHEX(0x000000) forState:UIControlStateNormal];
    [self.customNaviBar.leftButton setTitle:GSLoginLocalized(@"Back") forState:UIControlStateNormal];
    self.customNaviBar.leftButton.tintColor = [UIColor blackColor];
    
    __weak typeof(self) wself = self;
    self.customNaviBar.didClickedNaviLeftButton = ^{
        [wself didClickedNaviLeftButton];
    };
    self.customNaviBar.didClickedNaviRightButton = ^{
        [wself didClickedNaviRightButton];
    };
    self.customNaviBar.didTappedNaviTitle = ^{
        [wself didClickedNaviTitle];
    };
    [self.view addSubview:self.customNaviBar];
    [self.customNaviBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.width.equalTo(self.view);
        make.centerX.equalTo(self.view);
        make.height.mas_equalTo(GSLOGIN_Height_NavBar);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setTitle:(NSString *)title {
    [super setTitle:title];
    self.customNaviBar.titleLabel.text = title;
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (self.customNaviBar&&[self.customNaviBar isDescendantOfView:self.view]) {
        [self.view bringSubviewToFront:self.customNaviBar];
    }
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
}


- (void)didClickedNaviLeftButton {
    [self.view endEditing:true];
    if (self.navigationController.viewControllers.count == 1) {
        
        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    }else {
        
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)didClickedNaviRightButton {
    
}

- (void)didClickedNaviTitle {
    
}

@end
